package com.kd.service.jobSeeker.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kd.bean.admin.AdminBasic;
import com.kd.bean.admin.AdminRec;
import com.kd.bean.jobSeeker.Report_recruitment_msg;
import com.kd.bean.jobSeeker.Report_recruitment_person;
import com.kd.dao.admin.IAdminBasicDao;
import com.kd.dao.admin.IAdminRecDao;
import com.kd.dao.jobSeeker.IReport_recruitment_msgDao;
import com.kd.dao.recruiter.IRecruitment_msgDao;
import com.kd.service.jobSeeker.IReport_recruitment_msgService;
/**
 * 求职者相关的类
 * --举报招聘信息（Report_recruitment_msgServiceImpl）--
 * 数据服务层
 * @author ZFC
 *
 */
@Service
@Transactional
public class Report_recruitment_msgServiceImpl implements IReport_recruitment_msgService{

	@Autowired
	private IReport_recruitment_msgDao reportDao;//求职者相关的类 --举报招聘信息（IReport_recruitment_msgDao）-- 数据持久层
	
	@Autowired
	private IAdminBasicDao adminBasicDao;//管理员相关的类 --管理员-求职者->我的消息（AdminBasic）--
	
	@Autowired
	private IAdminRecDao adminRecDao;//管理员相关的类 --管理员-招聘者->我的消息（AdminRec）--
	
	@Override
	public PageInfo<Report_recruitment_msg> queryAllRri_report_state(Integer pageNum, Integer pageSize)
			throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Report_recruitment_msg> list = reportDao.queryAllRri_report_state();
		PageInfo<Report_recruitment_msg> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public Boolean updateRri_report_state(Integer rri_id, Integer rri_report_state,Integer admin_id) throws Exception {
		//通过举报招聘信息id查询举报者信息
		Report_recruitment_msg recruitmentMsg = reportDao.queryByRri_id(rri_id);
		if(rri_report_state==2) {
			//2代表审核通过
			
			//管理员给求职者发送举报成功的消息
			AdminBasic adminBasic = new AdminBasic();
			adminBasic.setBasic_id(recruitmentMsg.getBasic_information().getBasic_id());//求职者id
			adminBasic.setAdminRec_news_context("举报成功，感谢支持！！！");//消息内容
			adminBasic.setAdmin_id(admin_id);
			adminBasicDao.insertBasicJuBaoMessage(adminBasic);
			
			//管理员给招聘者发送被举报成功的消息
			AdminRec adminRec = new AdminRec();
			adminRec.setRecruiter_id(recruitmentMsg.getRecruitment_msg().getRecruiter_id());//招聘者id
			adminRec.setAdminRec_news_context("您旗下的招聘信息经核实有该操作，已被下架");//消息内容
			adminRec.setAdmin_id(admin_id);
			adminRecDao.insertRecJuBaoMessage(adminRec);
		}else {
			//管理员给求职者发送举报失败的消息
			AdminBasic adminBasic = new AdminBasic();
			adminBasic.setBasic_id(recruitmentMsg.getBasic_information().getBasic_id());//求职者id
			adminBasic.setAdminRec_news_context("举报失败，感谢支持！！！");//消息内容
			adminBasic.setAdmin_id(admin_id);
			adminBasicDao.insertBasicJuBaoMessage(adminBasic);
		}
		return reportDao.updateRri_report_state(rri_id, rri_report_state)>0;
	}

	@Override
	public Boolean insertReport_recruitment_msg(Report_recruitment_msg report_recruitment_msg) throws Exception {
		
		return reportDao.insertReport_recruitment_msg(report_recruitment_msg)>0;
	}

}
